/**
 * // -------------------------------------------------------------------------
/**
 *  Represents a block of memory in the binary file whether free or taken.
 *
 *  @author Erik Rodriguez and Cory Chase
 *  @version Apr 10, 2013
 */
public class MemBlock{
	
    private int length;  //In bytes
    private int offset;  //In bytes

    // ----------------------------------------------------------
    /**
     * Create a new memory block of a given offset and length
     * @param len
     * @param off
     */
    public MemBlock(int len, int off)
    {
        length = len;
        offset = off;
    }

    // ----------------------------------------------------------
    /**
     * Return the length in bytes of the memory block
     * @return the length
     */
    public int getLength()
    {
        return length;
    }
    
    /**
     * Converts the length from length in in characters to length in bytes
     */
    public void convertToByteLength(){
    	length = ((int)Math.ceil(length/4.));
    }

    // ----------------------------------------------------------
    /**
     * Return the offset starting position, in bytes, of the memory block.
     * @return the offset
     */
    public int getOffset()
    {
        return offset;
    }

    // ----------------------------------------------------------
    /**
     * Return the location of the end of the memory block
     * @return the end byte location
     */
    public int getEnd()
    {
    	return offset + length - 1;
    }

    // ----------------------------------------------------------
    /**
     * Appends another memory block to this one.
     * @param m another memory block
     */
    public void appendMemBlock(MemBlock m)
    {
        length += m.getLength();
    }

    // ----------------------------------------------------------
    /**
     * Adds a memory block to the beginning of this memory block.
     * @param m a new memory block
     */
    public void prependMemBlock(MemBlock m){
    	length += m.getLength();
    	offset = offset - m.getLength() - 1;
    }

    // ----------------------------------------------------------
    /**
     * Place a description of your method here.
     * @param sizeToShrink
     * @return the shrunk memblock
     */
    public MemBlock shrink(int sizeToShrink)
    {
    	int oldOffset = offset;
    	offset += sizeToShrink;
    	length -= sizeToShrink;

    	return new MemBlock(sizeToShrink, oldOffset);
    }

    // ----------------------------------------------------------
    /**
     * Expand a memory block. Used for free space mem blocks.
     * @param sizeToExpand
     * @return the expanded memblock
     */
    public MemBlock expand(int sizeToExpand){
    	length += sizeToExpand;
    	return this;
    }

}